<?php defined('SYSPATH') or die('No direct script access.');
require ('application/classes/dao/base.php');
class Controller_storem extends Controller {


	public function action_index(){
		echo View::factory('manager/store');
	}

    public function check(){
        $parm = post($this->request);
        // print_r($parm);
        if(!isset($parm['province']) ||($parm['province'])==""){
            echo "省份不能为空";
            exit;
        }
        if(!isset($parm['city']) ||($parm['city'])==""){
            echo "城市不能为空";
            exit;
        }
        if(!isset($parm['address']) ||($parm['address'])==""){
            echo "地址不能为空";
            exit;
        }
        if(!isset($parm['longitude']) ||($parm['longitude'])==""){
            echo "经度不能为空";
            exit;
        }
        if(!isset($parm['latitude']) ||($parm['latitude'])==""){
            echo "纬度不能为空";
            exit;
        }
        if(!isset($parm['isget']) ||($parm['isget'])==""){
            echo "门店自提不能为空";
            exit;
        }
        if(!isset($parm['isstore']) ||($parm['isstore'])==""){
            echo "门店自提不能为空";
            exit;
        }
    }
	public function action_insert(){
        $parm = post($this->request);
		self::check();
        $result = rpcCall("store.add",$parm);

		echo "<script>window.location.href='".Url::base()."index.php/storem/index'</script>";
	}
	public function action_updatestore(){
        $parm = post($this->request);
        self::check();
        $result = rpcCall("store.update",$parm);

        echo "<script>window.location.href='".Url::base()."index.php/storem/index'</script>";
    }
	public function action_add(){
		$result = rpcCall("china.getProvince",null);
		echo View::factory('manager/map')->bind("china",$result);
	}
	public function action_detail(){
		$parm = get($this->request);
		if(!isset($parm['id']) ||($parm['id'])==""){
        	echo "门店自提不能为空";
            exit;
        }
		$result = rpcCall("china.getProvince",null);
		$bean =  rpcCall("store.detail",$parm['id']);
		echo View::factory('manager/updatestore')->bind("china",$result)->set("store",$bean);
	}
	public function action_getData(){

		$parm = get($this->request);
		if(!isset($parm['page']) ||($parm['page'])==""){
        	echo "page不能为空";
            exit;
        }
        if(!isset($parm['rows']) ||($parm['rows'])==""){
        	echo "rows能为空";
            exit;
        }

        $data=rpcCall("store.listdata",$parm);
        echo json_encode($data);
	}
}
